//
//  LFYHomeViewController.m
//  loanForYou
//
//  Created by 刘威 on 2017/5/9.
//  Copyright © 2017年 刘威. All rights reserved.
//

#import "LFYHomeViewController.h"
#import "SYWebViewController.h"
#import "SDCycleScrollView.h"
#import "LFYHomeModel.h"
#import <UMMobClick/MobClick.h>
#import "LFYTestViewController.h"

@interface LFYHomeViewController () <UITableViewDelegate,UITableViewDataSource,SDCycleScrollViewDelegate,LFYHomeViewControllerSortCellDelegate> {
    SDCycleScrollView *_tableHeaderView;
    NSInteger   _page;
    NSInteger   _size;
    LFYHomeModel *_categoryModel;
    UIView      *_titleView;
    BOOL        _canShow;
    NSArray *_testTitleArray;
    NSArray *_testValueArray;
}

@property (strong, nonatomic) UITableView *tableView;

@property (strong, nonatomic) NSMutableArray *dataArray;
@property (strong, nonatomic) NSMutableArray *bannderArray;


@end

@implementation LFYHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"贷攻略";
    
    _testTitleArray = @[@"教你快速申请小额贷款",@"无抵押大额贷款如何申请",@"车辆抵押贷款需要什么手续",@"马力钱包借款攻略",@"闪银借款攻略"];
    
    _testValueArray = @[@"网金融这个大环境下，做金融贷款的公司逐渐增多，也为广大群众提供了更多的选择。但是也不乏一些心术不正的骗子打着公司小额贷款的旗号骗取钱财。所以在进行贷款的时候要慎重，那些你一找他们贷款就让你交钱的信贷公司还是不要考虑了，多数是骗子。在申请贷款时要擦亮双眼，不要一步步踏入他们的陷阱。\n其次，用信用卡贷款也是一个不错的选择。但是还款的时候要注意，一定要按时还款，如果忘记还款，贷款逾期的话会影响你的信誉值，另外还将面临高额的利息。信用卡的贷款在额度内可是随用随有的，方便快捷的特性也让它在大家的生活中生根发芽，让更多的人享受到它所带来的便利。\n第三种是在典当行申请贷款，如果家里面有价值较高的东西，可以在典当行做抵押，贷款也是很快的。这对于急需用钱的人也是个不错的选择。\n第四种是找一些能进行贷款的软件申请贷款。现在金融公司以“互联网+金融”的形式进行贷款的项目比比皆是，下款快、操作简单，同样可以缓解短时间内资金周转不开的情况。",@"与抵押贷款相比，无抵押贷款额度相对较小，其主要原因是，无抵押贷款不需要借款人提供任何抵（质）押物作担保，从而提高了贷款机构的信贷风险，为了控制这一风险保障顺利收回贷款，他们不得不这样做。但是，这并不意味着无法申请无抵押大额贷款，如果申请人资质够好的话，申请无抵押大额贷款也是没有问题的。那么，无抵押大额贷款如何申请？\n无抵押大额贷款申请要件：\n一、良好的个人信用\n无抵押贷款本质上是一种信用贷款，除了对个人资质要求高之外，良好的信用记录更是银行考察的重点。如果借款人出现了逾期的情况，就很有可能被银行拒贷。\n另外，在生活中的其他消费，如电费、电话费、房贷月供也需要做到按时足额缴纳，一旦出现逾期情况，则很有可能导致办理额度低或办理不了贷款。\n二、较好的自身资质\n无抵押贷款对借款人的个人资质要求很高，最低条件是每月打卡工资在4000元以上，就算手中有流动资金，如果不能提供固定的银行流水，也会遭到银行拒贷。\n除了收入要稳定，优良的职业更是无抵押贷款的重要条件，如公务员、教师、500强企业员工、公司高层管理等，这样工作的人群往往更能获得大额无抵押贷款。\n三、选对正确的银行\n借款人在办理无抵押贷款的时候，由于每家银行的情况和标准不同，所以对借款人的要求不同，考察的侧重点也不同。一般来说，外资银行和中资银行在贷款的审核上可能存在差异，中资银行审核较为严格，而外资银行一般就相对宽松些。\n但是在办理费用上，可能外资银行的收费会比较高一些。在办理无抵押贷款时要根据个人自身情况选择贷款银行，这样可以达到事半功倍的效果。\n四、提供财力证明\n如果你名下有房产、汽车，就不要吝啬这些财力证明了!据悉，申请无抵押贷款的借款人如果能提供本人名下的房产证、车辆行驶证等证明材料，不但能轻松拿到大额无抵押贷款，而且贷款利率也较低。\n无抵押大额贷款申请技巧：\n技巧一：擅于贷比三家\n从目前来看，各贷款机构对借款人的要求并非一致，设定的最高额度也有差异，只要你耐心的多找几家机构对比，很有可能如愿以偿的拿到大额无抵押贷款。\n技巧二：找非银行金融机构\n由于银行与央行征信系统连接，所以借款人只要和银行发生信贷关系，其记录都会在个人信用报告上体现，若有一次两次的逾期还款行为，便会影响下次贷款。\n但是，目前与央行征信系统相连的非银行金融机构却很少，有大额资金需求的借款人不妨利用这个机会，多找几家非银行金融机构办理无抵押贷款，从而解决大额资金需求难题，但是这样做会提高贷款成本。\n技巧三：亮出资产证明\n有大额无抵押贷款需求的借款人，若名下有房产、汽车、有价证券等资产，那么就不要吝啬了，贷款时不妨大方的向贷款机构亮出相关证明，为自己的贷款申请加分。有些人会担心这样资产会被贷款机构抵押，事实上并不会，他们需要的只是一个保障，所以只会收取复印件，不会办理抵押登记手续。",@"贷款的时候如果能提供一定的抵押物，会加快获贷的速度，也会加大获贷的额度，但是在办理之前要知道有哪些手续。那么，车辆抵押贷款需要什么手续？\n车辆抵押贷款需要什么手续？\n1、借款人本人有效身份证件；\n2、有效居住证明、收入证明；\n3、机动车登记证、行驶证、购置附加税证(本)、购车发票；\n4、保险单、车船税、进口车辆相关税证明；\n5、贷款机构要求提供的另外的手续。\n车辆抵押贷款需要什么流程？\n1、贷款机构收到申请人提供的资料；\n2、对申请人进行家访、调查以及预估车辆价值；\n3、贷款机构初步预定贷款额度；\n4、办理委托公证；\n5、贷款机构收押申请人相关证件；\n6、贷款机构放款。",@"申请渠道：\n应用市场搜索【马力钱包】，下载苹果或者安卓app填资料申请即可\n口子介绍：\n借款额度：500-10000元\n借款期限：1-12个月\n借款利息：月息0.8%\n还款方式：等额本息，随借随还\n申请条件：\n1、年龄18 周岁以上的中国公民。\n2、没有不良征信记录。\n必填信息：\n1、身份证信息。\n2、填写联系人信息。\n3、认证手机运营商。\n提高额度：\n医保或社保卡、公积金缴纳证明、房产证、行驶证、银行流水照片等\n注意事项：\n马力钱包的出品方是廊坊市玖壹网络科技有限公司，APP内的信息却全是瓜牛钱包的，估计是瓜牛钱包的马甲。知道就行了。新口子一般不太稳定，下款率未知，最好等有下款案例后再申请。",@"1产品介绍：闪银\n2申请方式：线上申请\n3必要材料：个人信息、实名手机、支付宝芝麻信用分授权\n4能撸金额10万\n办理流程：\n1、应用市场搜索：闪银\n2、下载APP并完成注册\n3、验证个人信息。\n4、授权大数据、手机、淘宝、京东（30分钟内完成可立即审批额度）；\n5、10分钟左右等待批款\n4：放款金额：最高10元\n5：平均月利率：0.6%\n6：下款时间2小时\n7：平均下款率：55%\n8：平均下款金额：590万\n是否查征信：否\n是否查询大数据征信：是\n攻略：\n1保证信用卡账单完整度确保邮箱中至少有某一张卡过去六个月完整的账单。如果账单不全, 可以打银行客服申请补发电子账单。\n2呈现最好的自己如果有多张信用卡，可以先导入账单数据最多且没有逾期的信用卡。\n3删除可能造成不利的邮件其它网贷发来的各类邮件、在线博彩站点的邮件最好要处理一下。\n4贷款前3个月最好可以做一些信用流水，这样可以大幅提升你的信用授信额度！"];
    
    _page = -1;
    _size = 10;
    _dataArray = [NSMutableArray array];
    _bannderArray = [NSMutableArray array];
    // Do any additional setup after loading the view.
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.backgroundColor = [UIColor grayBackgroundColor];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.tableHeaderView = [self tableHeaderView];
    WS(weakSelf);
    
    _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        _page = -1;
        [weakSelf requestShow];
    }];
    
    _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        [weakSelf requestData];
    }];
    [self.view addSubview:_tableView];
    [_tableView makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.top.mas_equalTo(self.view);
    }];
    
    if ([Tool getFileCache:HOMEBOOLSHOWKEY]) {
        id responseObject = [Tool getFileCache:HOMEBOOLSHOWKEY];
        LFYShowModel *model = [[LFYShowModel alloc] initWithDictionary:(NSDictionary *)responseObject error:nil];
        if (model.data && [model.data boolValue]) {
            _canShow = YES;
        } else
            _canShow = NO;
    }
    
    if (_canShow) {
        if ([Tool getFileCache:HOMECATEGORYKEY]) {
            id responseObject = [Tool getFileCache:HOMECATEGORYKEY];
            _categoryModel = [[LFYHomeModel alloc] initWithDictionary:(NSDictionary *)responseObject error:nil];
            [_tableView reloadData];
        }
        
        if ([Tool getFileCache:HOMECATEGORYDATAKEY]) {
            id responseObject = [Tool getFileCache:HOMECATEGORYDATAKEY];
            LFYHomeModel *model = [[LFYHomeModel alloc] initWithDictionary:(NSDictionary *)responseObject error:nil];
            if (model.data) {
                [_dataArray removeAllObjects];
                [_dataArray addObjectsFromArray:model.data];
                [_tableView reloadData];
            }
        }
        
        if ([Tool getFileCache:HOMEBANNERDATAKEY]) {
            id responseObject = [Tool getFileCache:HOMEBANNERDATAKEY];
            LFYHomeModel *model = [[LFYHomeModel alloc] initWithDictionary:(NSDictionary *)responseObject error:nil];
            if (model.data) {
                [_bannderArray removeAllObjects];
                [_bannderArray addObjectsFromArray:model.data];
                NSMutableArray *array = [NSMutableArray array];
                for (NSInteger i = 0; i < model.data.count; i++) {
                    LFYHomeModelItem *data = model.data[i];
                    [array addObject:[NSString stringWithFormat:@"%@%@",HOST_IMAGE,data.imgUrl]];
                }
                _tableHeaderView.imageURLStringsGroup = array;
            }
        }
    } else {
        [self createTestData];
    }
    
    [self requestShow];
}

- (void)createTestData {
    [self.tableView.mj_footer endRefreshingWithNoMoreData];
    [self.tableView.mj_footer setHidden:YES];
#pragma mark - banner
    UIImage *image1 = [UIImage imageNamed:@"banner1_icon"];
    UIImage *image2 = [UIImage imageNamed:@"banner2_icon"];
    _tableHeaderView.localizationImageNamesGroup = @[image1,image2];
    
#pragma mark - categroy
    _categoryModel = [[LFYHomeModel alloc] init];
    NSArray *titleArray = @[@"小额攻略",@"大额技巧",@"车抵流程"];
    NSArray *imageArray = @[@"left_icon",@"center_icon",@"right_icon"];
    NSMutableArray<LFYHomeModelItem> *valueArray = [NSMutableArray<LFYHomeModelItem> array];
    for (NSInteger i = 0; i < 3; i++) {
        LFYHomeModelItem *data = [[LFYHomeModelItem alloc] init];
        data.topic = titleArray[i];
        data.test_image = imageArray[i];
        data.weight = [NSString stringWithFormat:@"%ld",i + 1];
        [valueArray addObject:data];
    }
    _categoryModel.data = valueArray;
    
#pragma mark - tableView
    
    
    [_dataArray removeAllObjects];
    LFYHomeModelItem *item1 = [[LFYHomeModelItem alloc] init];
    item1.productName = @"马力钱包借款攻略";
    item1.test_image = @"list1_icon";
    item1.desc = @"点评：纯信用借款，5分钟申请，100秒到账";
    item1.priceRange = @"类型：小额信贷";
    item1.priceDesc = @"对象：大学生、白领";
    item1.rightTopic = @"查看详情";
    [_dataArray addObject:item1];
    
    LFYHomeModelItem *item2 = [[LFYHomeModelItem alloc] init];
    item2.productName = @"闪银快速借款攻略";
    item2.test_image = @"list2_icon";
    item2.desc = @"点评：3分钟审批，下款快";
    item2.priceRange = @"类型：小额信贷";
    item2.priceDesc = @"对象：18岁以上";
    item2.rightTopic = @"查看详情";
    [_dataArray addObject:item2];
    
    [_tableView reloadData];
}

- (void)requestShow {
    WS(weakSelf);
    [[SYHttpManager sharedHttpManager]requestGet:get_home_show_url parameters:nil success:^(id responseObject) {
        LFYShowModel *model = [[LFYShowModel alloc] initWithDictionary:(NSDictionary *)responseObject error:nil];
        if (model.data && [model.data boolValue]) {
            _canShow = YES;
            
        } else {
            _canShow = NO;
        }
//        _canShow = !_canShow;
        if (_canShow) {
            [weakSelf requestData];
            [weakSelf requestBannerData];
            [weakSelf requestCategoryData];
        } else {
            [weakSelf createTestData];
        }
        
        
        [weakSelf.tableView.mj_header endRefreshing];
        [Tool setFileCache:HOMEBOOLSHOWKEY value:responseObject];
    } failure:^(NSError *error) {
        [weakSelf.tableView.mj_header endRefreshing];
        if ([Tool getFileCache:HOMEBOOLSHOWKEY]) {
            
        } else {
            [weakSelf requestShow];
        }
    }];
}

- (void)requestCategoryData {
    WS(weakSelf);
    [[SYHttpManager sharedHttpManager]requestGet:get_home_category_url parameters:@{} success:^(id responseObject) {
        _categoryModel = [[LFYHomeModel alloc] initWithDictionary:(NSDictionary *)responseObject error:nil];
        if (_categoryModel && _categoryModel.data.count) {
            [Tool setFileCache:HOMECATEGORYKEY value:responseObject];
            [weakSelf.tableView reloadData];
        }
    } failure:^(NSError *error) {
        if ([Tool getFileCache:HOMECATEGORYKEY]) {
            
        } else {
            [weakSelf requestCategoryData];
        }
    }];
}

- (void)requestBannerData {
    WS(weakSelf);
    [[SYHttpManager sharedHttpManager]requestGet:get_home_banner_url parameters:@{} success:^(id responseObject) {
        LFYHomeModel *model = [[LFYHomeModel alloc] initWithDictionary:(NSDictionary *)responseObject error:nil];
        if (model && model.data.count) {
            if (_page == 0) {
                [Tool setFileCache:HOMEBANNERDATAKEY value:responseObject];
                [_bannderArray removeAllObjects];
            }
            [_bannderArray addObjectsFromArray:model.data];
            NSMutableArray *array = [NSMutableArray array];
            for (NSInteger i = 0; i < model.data.count; i++) {
                LFYHomeModelItem *data = model.data[i];
                [array addObject:[NSString stringWithFormat:@"%@%@",HOST_IMAGE,data.imgUrl]];
            }
            _tableHeaderView.imageURLStringsGroup = array;
        }
    } failure:^(NSError *error) {
        if ([Tool getFileCache:HOMEBANNERDATAKEY]) {
            
        } else {
            [weakSelf requestBannerData];
        }
    }];
}

- (void)requestData {
    WS(weakSelf);
    _page++;
    [[SYHttpManager sharedHttpManager]requestGet:get_home_recomment_url parameters:@{@"page":@(_page),@"size":@(_size)} success:^(id responseObject) {
        [weakSelf.tableView.mj_header endRefreshing];
        LFYHomeModel *model = [[LFYHomeModel alloc] initWithDictionary:(NSDictionary *)responseObject error:nil];
        if (model && model.data.count) {
            if (_page == 0) {
                [Tool setFileCache:HOMECATEGORYDATAKEY value:responseObject];
                [_dataArray removeAllObjects];
            }
            [_dataArray addObjectsFromArray:model.data];
            
            [weakSelf.tableView reloadData];
            if (model.data.count < _size) {
                [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
                [weakSelf.tableView.mj_footer setHidden:YES];
            } else {
                [weakSelf.tableView.mj_footer endRefreshing];
                [weakSelf.tableView.mj_footer setHidden:NO];
            }
        } else {
            
        }
    } failure:^(NSError *error) {
        [weakSelf.tableView.mj_header endRefreshing];
        [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
        [weakSelf.tableView.mj_footer setHidden:YES];
        if ([Tool getFileCache:HOMECATEGORYDATAKEY]) {
            
        } else {
            _page = -1;
            [weakSelf requestData];
        }
    }];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (_tableHeaderView) {
        [_tableHeaderView adjustWhenControllerViewWillAppera];
    }
}

- (SDCycleScrollView *)tableHeaderView {
    if (!_tableHeaderView) {
        _tableHeaderView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH / 2.0f) delegate:self placeholderImage:[UIImage imageNamed:@"long_default_image_icon"]];
        _tableHeaderView.backgroundColor = [UIColor grayBackgroundColor];
        
        _tableHeaderView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
        _tableHeaderView.pageDotColor = [UIColor whiteColor];
        _tableHeaderView.currentPageDotColor = [UIColor redButtonColor];
        _tableHeaderView.autoScrollTimeInterval = 5;
    }
    return _tableHeaderView;
}

#pragma cell - delegate
- (void)LFYSortCellButtonClick:(LFYHomeModelItem *)data {
    if (data.contentUrl.length && _canShow) {
        [MobClick event:@"home_category" attributes:@{data.topic?data.topic:@"category":data.contentUrl}];
        SYWebViewController *vc = [[SYWebViewController alloc] init];
        vc.requestUrl = [NSURL URLWithString:data.contentUrl];
        [self.navigationController pushViewController:vc animated:YES];
    } else {
        LFYTestViewController *vc = [[LFYTestViewController alloc] init];
        vc.topTitle = _testTitleArray[[data.weight integerValue] - 1];
        vc.navTitle = _testTitleArray[[data.weight integerValue] - 1];
        vc.content = _testValueArray[[data.weight integerValue] - 1];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

#pragma mark - bannerDelegate
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    if (_bannderArray.count) {
        LFYHomeModelItem *data = _bannderArray[index];
        if (data.contentUrl.length && _canShow) {
            [MobClick event:@"home_banner" attributes:@{data.title? data.title : @"banner" :data.contentUrl}];
            SYWebViewController *vc = [[SYWebViewController alloc] init];
            vc.requestUrl = [NSURL URLWithString:data.contentUrl];
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
}

#pragma mark - tableView

#pragma mark - table - dataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1 + _dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section) {
        LFYHomeViewControllerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"c"];
        if (!cell) {
            cell = [[LFYHomeViewControllerCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"c"];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        if (_dataArray.count) {
            cell.data = _dataArray[indexPath.section - 1];
        }
        return cell;
    } else {
        LFYHomeViewControllerSortCell *cell = [tableView dequeueReusableCellWithIdentifier:@"s"];
        if (!cell) {
            cell = [[LFYHomeViewControllerSortCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:@"s"];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.delegate = self;
        }
        cell.model = _categoryModel;
        return cell;
    }
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section) {
        LFYHomeModelItem *data = _dataArray[indexPath.section - 1];
        if (data.contentUrl.length && _canShow) {
            SYWebViewController *vc = [[SYWebViewController alloc] init];
            vc.requestUrl = [NSURL URLWithString:data.contentUrl];
            [MobClick event:@"home_product" attributes:@{data.productName?data.productName:@"product":data.contentUrl}];
            [self.navigationController pushViewController:vc animated:YES];
        } else if (indexPath.section < 3) {
            LFYTestViewController *vc = [[LFYTestViewController alloc] init];
            vc.topTitle = _testTitleArray[indexPath.section + 2];
            vc.navTitle = _testTitleArray[indexPath.section + 2];
            vc.content = _testValueArray[indexPath.section + 2];
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section) {
        return 130;
    }
    return 110;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 1) {
        if (!_titleView) {
            _titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 35)];
            UILabel *label = [[UILabel alloc] init];
            label.font = [UIFont titleFont];
            label.textColor = [UIColor grayContentColor];
            [_titleView addSubview:label];
            label.text = @"热门推荐";
            [label makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.centerY.mas_equalTo(_titleView);
            }];
            
            UIView *lineView1 = [[UIView alloc] init];
            lineView1.backgroundColor = [UIColor cuttingLineColor];
            [_titleView addSubview:lineView1];
            [lineView1 makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(_titleView.mas_left).offset(15);
                make.right.equalTo(label.mas_left).offset(-15);
                make.centerY.equalTo(label.mas_centerY);
                make.height.equalTo(@(0.5));
            }];
            
            UIView *lineView2 = [[UIView alloc] init];
            lineView2.backgroundColor = [UIColor cuttingLineColor];
            [_titleView addSubview:lineView2];
            [lineView2 makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(label.mas_right).offset(15);
                make.right.equalTo(_titleView.mas_right).offset(-15);
                make.centerY.equalTo(label.mas_centerY);
                make.height.equalTo(@(0.5));
            }];
        }
        return _titleView;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
//    return 0.01f;

    if (section == 1) {
        return 35.0f;
    }
    return 0.01f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if (section == 0) {
        return 0.01f;
    }
    return 10.0f;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end



@implementation LFYHomeViewControllerSortCell {
    NSMutableArray *_imageArray;
    NSMutableArray *_titleArray;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _imageArray = [NSMutableArray array];
        _titleArray = [NSMutableArray array];
        for (NSInteger i = 0; i < 3; i++) {
            UIImageView *imageView = [[UIImageView alloc] init];
            [self.contentView addSubview:imageView];
            imageView.userInteractionEnabled = YES;
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageClick:)];
            imageView.tag = 100 + i;
            [imageView addGestureRecognizer:tap];
            [imageView makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(self.mas_centerY).offset(-10);
                make.centerX.equalTo(self.mas_centerX).offset(SCREEN_WIDTH / 3 * (i - 1));
                make.size.mas_equalTo(CGSizeMake(45, 45));
            }];
            [_imageArray addObject:imageView];
            
            UILabel *contentLabel = [[UILabel alloc] init];
            contentLabel.textColor = [UIColor grayContentColor];
            contentLabel.font = [UIFont contentFont];
            contentLabel.textAlignment = NSTextAlignmentCenter;
            [self.contentView addSubview:contentLabel];
            [contentLabel makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.equalTo(imageView.mas_centerX);
                make.top.equalTo(imageView.mas_bottom).offset(10);
            }];
            [_titleArray addObject:contentLabel];
        }
    }
    return self;
}

- (void)setModel:(LFYHomeModel *)model {
    _model = model;
    if (model.data.count > 2) {
        for (NSInteger i = 0; i < 3; i++) {
            LFYHomeModelItem *data = model.data[i];
            UIImageView *imageView = _imageArray[i];
            UILabel *label = _titleArray[i];
            label.text = data.topic;
            if (data.test_image.length) {
                [imageView setImage:[UIImage imageNamed:data.test_image]];
            } else
                [imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HOST_IMAGE,data.iconUrl]] placeholderImage:[UIImage imageNamed:@"default_image_icon"]];
            
        }
    }
}

- (void)imageClick:(UITapGestureRecognizer *)tap {
    NSInteger index = tap.view.tag - 100;
    if (_model.data.count > 2 && _delegate && [_delegate respondsToSelector:@selector(LFYSortCellButtonClick:)]) {
        [_delegate LFYSortCellButtonClick:_model.data[index]];
    }
}

- (void)setDelegate:(id<LFYHomeViewControllerSortCellDelegate>)delegate {
    _delegate = delegate;
}

@end

@implementation LFYHomeViewControllerCell {
    UILabel *_titleLabel;
    UIImageView *_imageView;
    UILabel *_contentLabel;
    UILabel *_moneyLabel;
    
    UILabel *_rightTopLabel;
    UILabel *_mLabel;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        UIImageView *imageView = [[UIImageView alloc] init];
        _imageView = imageView;
        [self.contentView addSubview:imageView];
        [imageView makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_left).offset(15);
            make.top.equalTo(self.mas_top).offset(10);
            make.size.mas_equalTo(CGSizeMake(30, 30));
        }];
        imageView.layer.masksToBounds = YES;
        imageView.layer.cornerRadius = 4;
        
        UILabel *titleLabel = [[UILabel alloc] init];
        _titleLabel = titleLabel;
        titleLabel.textColor = [UIColor contentColor];
        titleLabel.font = [UIFont navControllerTitleFont];
        titleLabel.text = @"title";
        [self.contentView addSubview:titleLabel];
        [titleLabel makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(imageView.mas_right).offset(15);
            make.centerY.equalTo(imageView.mas_centerY).offset(0);
            make.right.equalTo(self.mas_right).offset(-15);
        }];
        
        
        UILabel *rightLabel = [[UILabel alloc] init];
        rightLabel.textColor = [UIColor redMoneyColor];
        rightLabel.font = [UIFont titleFont];
        rightLabel.text = @"立即申请";
        _rightTopLabel = rightLabel;
        [self.contentView addSubview:rightLabel];
        [rightLabel makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.mas_right).offset(-15);
            make.centerY.equalTo(titleLabel.mas_centerY).offset(0);
        }];
        
        
        UIView *lineView = [[UIView alloc] init];
        lineView.backgroundColor = [UIColor cuttingLineColor];
        [self.contentView addSubview:lineView];
        [lineView makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(self);
            make.height.equalTo(@(0.5f));
            make.top.equalTo(imageView.mas_bottom).offset(10);
        }];
        
        UIView *bigView = [[UIView alloc] init];
        [self.contentView addSubview:bigView];
        [bigView makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_equalTo(self);
            make.top.equalTo(lineView.mas_bottom);
        }];
        
        
        UIView *lineView1 = [[UIView alloc] init];
        lineView1.backgroundColor = [UIColor cuttingLineColor];
        [bigView addSubview:lineView1];
        [lineView1 makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(0.5));
            make.top.equalTo(bigView.mas_top).offset(15);
            make.bottom.equalTo(bigView.mas_bottom).offset(-15);
            make.centerX.equalTo(self.mas_centerX);
        }];
        
        
        
        UILabel *contentLabel = [[UILabel alloc] init];
        _contentLabel = contentLabel;
        contentLabel.numberOfLines = 3;
        contentLabel.textAlignment = NSTextAlignmentCenter;
        contentLabel.textColor = [UIColor grayContentColor];
        contentLabel.font = [UIFont titleFont];
        contentLabel.text = @"content";
        [bigView addSubview:contentLabel];
        [contentLabel makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(lineView1.mas_right).offset(15);
            make.centerY.equalTo(bigView.mas_centerY).offset(-0);
            make.right.equalTo(self.mas_right).offset(-15);
        }];
        
        UILabel *moneyLabel = [[UILabel alloc] init];
        _moneyLabel = moneyLabel;
        moneyLabel.textColor = [UIColor redMoneyColor];
        moneyLabel.font = [UIFont nameFont];
        moneyLabel.textAlignment = NSTextAlignmentCenter;
        moneyLabel.text = @"content";
        [bigView addSubview:moneyLabel];
        [moneyLabel makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_left).offset(15);
            make.bottom.equalTo(bigView.mas_centerY).offset(-2);
            make.right.equalTo(lineView1.mas_left).offset(-15);
        }];
        
        UILabel *label = [[UILabel alloc] init];
        label.textColor = [UIColor grayContentColor];
        label.font = [UIFont titleFont];
        label.textAlignment = NSTextAlignmentCenter;
        label.text = @"额度范围(元)";
        _mLabel = label;
        [bigView addSubview:label];
        [label makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(moneyLabel.mas_bottom).offset(5);
            make.centerX.equalTo(moneyLabel.mas_centerX);
        }];
    }
    return self;
}

- (void)setData:(LFYHomeModelItem *)data {
    _data = data;
    _titleLabel.text = data.productName;
    _contentLabel.text = data.desc;
    _moneyLabel.text = data.priceRange;
    _mLabel.text = data.priceDesc;
    _rightTopLabel.text = data.rightTopic;
    if (data.test_image.length) {
        [_imageView setImage:[UIImage imageNamed:data.test_image]];
    } else
        [_imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HOST_IMAGE,data.logoUrl]] placeholderImage:[UIImage imageNamed:@"default_image_icon"]];

}


@end
